﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using BISPOS.Repository;

namespace BISPOS
{
    public partial class ChangePriceXtraForm : DevExpress.XtraEditors.XtraForm
    {
        ProductRepository repo = new ProductRepository();
        Product product;
        EditProductUserControl editProductUserControl;
        ProductRepository productRepository = new ProductRepository();
        public ChangePriceXtraForm(Product _product,EditProductUserControl _editProductUserControl)
        {
            InitializeComponent();
            product = _product;
            editProductUserControl = _editProductUserControl;
            textEdit1.Text = product.Name;
            textEdit2.Name = product.CurrentPrice.Amount.ToString("n2");
            textEdit3.Focus();
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            try
            {
                repo.AddPrice(Convert.ToDecimal(textEdit3.Text), product.Id, DateTime.Now, null, "", true);
                editProductUserControl.groupControl2.Controls.Clear();
                ProductDetail productDetailsUserControl = new ProductDetail(productRepository.Get(product.Id),editProductUserControl);
                editProductUserControl.groupControl2.Controls.Add(productDetailsUserControl);
            }
            catch 
            {
                MessageBox.Show("ผิดพลาด");
            }
        }
    }
}